/*
 * test_014:
 * KCacheGrind tests
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

struct vector {
	long	*data;
	int	n;
	int	size;
};


#define SWAP_INT(a, b)	(((a) ^ (b)) && ((b) ^= (a) ^= (b), (a) ^= (b)))

void
swap_long(long *a, long *b)
{
	register long t = *a;
	*a = *b;
	*b = t;
}

static int
Quick_sort__partition(long *array, int L, int R)
{
	long		p = array[L];
	register int	i = L,
			j = R;

	while (i <= j) {
		while (array[i] < p)
			++i;
		while (array[j] > p)
			--j;
		if (i < j) {
			swap_long(&array[i], &array[j]);
			++i;
			--j;
		} else
			return j;
	}
	return j;
}

static void
Quick_sort__main(long *array, int left, int right)
{
	int m;

	if (left < right) {
		m = Quick_sort__partition(array, left, right);
		Quick_sort__main(array, left, m);
		Quick_sort__main(array, m+1, right);
	}
	return;
}

void
Quick_sort(long *array, int a_size)
{
	return Quick_sort__main(array, 0, a_size - 1);
}

static int
Quick_sort_rand__partition(long *array, int L, int R)
{
	long		p = array[(rand() % (R-L)) + L];
	register int	i = L, j = R;

	while (i <= j) {
		while (array[i] < p)
			++i;
		while (array[j] > p)
			--j;
		if (i < j) {
			swap_long(&array[i], &array[j]);
			++i;
			--j;
		} else
			return j;
	}
	return j;
}

static void
Quick_sort_rand__main(long *array, int left, int right)
{
	int m;

	if (left < right) {
		m = Quick_sort_rand__partition(array, left, right);
		Quick_sort_rand__main(array, left, m);
		Quick_sort_rand__main(array, m+1, right);
	}
	return;
}

void
Quick_sort_rand(long *array, int a_size)
{
	return Quick_sort_rand__main(array, 0, a_size - 1);
}

struct vector *
vector_init(void)
{
	struct vector *v;

	v = calloc(1, sizeof *v);
	v->n = 0;
	v->size = 8;
	v->data = calloc(v->size, sizeof *v->data);

	return v;
}

void
vector_append(struct vector *v, long key)
{
	if (v->n >= v->size) { /* v->n will increase */
		v->size *= 2;
		v->data = realloc(v->data, v->size * (sizeof *v->data));
	}
	v->data[v->n++] = key;
}

unsigned int
vector_destroy(struct vector *v)
{
	if (v->size)
		free(v->data);
	free(v);

	return 0U;
}

int
main(int argc, char **argv)
{
	struct vector	*v = NULL;
	long		in;
	register int	i = 0;
	register long	prev;
	double		avgdiff = 0.0;
	long		maxdiff = 0;

	v = vector_init();
	while (scanf("%ld", &in) == 1)
		vector_append(v, in);

	Quick_sort_rand(v->data, v->n);

	for (i = 0; i < v->n; i++) {
		avgdiff += v->data[i] - prev;
		if (maxdiff < v->data[i] - prev)
			maxdiff = v->data[i] - prev;

		prev = v->data[i];
	}
	avgdiff /= v->n;
	(void) printf("avgdiff=%g, maxdiff=%ld\n", avgdiff, maxdiff);
	vector_destroy(v);
	return 0;
}
